#include "main/utils.h"
using namespace std;

int longestFib(const vector<int>& arr) {
  int length = arr.size();
  vector<vector<int>> dp;
  dp.resize(length);
  for (int i = 0; i < length; ++i) {
    dp[i].resize(length, 2);
  }

  map<int, int> map;
  for (int i = 0; i < length; ++i) {
    map[arr[i]] = i;
  }

  int max_length = 2;
  for (int i = 1; i < length; ++i) {
    for (int j = 0; j < i; ++j) {
      int arr_k = arr[i] - arr[j];
      if (map.count(arr_k) != 0) {
        int k = map[arr_k];
        dp[i][j] = k < j ? dp[j][k] + 1 : 2;
        if (dp[i][j] > max_length) {
          max_length = dp[i][j];
        }
      }
    }
  }

  return max_length > 2 ? max_length : 0;
}

int main() {
  vector<int> arr = {1, 2, 3, 4, 5, 6, 7, 8};
  cout << longestFib(arr) << endl;

  return 0;
}
